import Vue from 'vue';
import Router from 'vue-router';

import Home from './views/Home';
import AddDoctor from './views/AddDoctor';
import UpdateDoctor from './views/UpdateDoctor';
import Intro from './views/Intro';

Vue.use(Router);

const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home,
      meta: {
        title: '首页 - 全义中医诊所'
      }
    },
    {
      path: '/doctor',
      name: 'addDoctor',
      component: AddDoctor,
      meta: {
        title: '新增医生 - 全义中医诊所'
      }
    },
    {
      path: '/doctors/:doctorId',
      name: 'updateDoctor',
      component: UpdateDoctor,
      meta: {
        title: '编辑医生信息 - 全义中医诊所'
      }
    },
    {
      path: '/intro/:key',
      name: 'intro',
      component: Intro,
      meta: {
        title: '诊所信息 - 全义中医诊所'
      }
    }
  ]
});

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next();
});

export default router;
